<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/mobile/include/taglib.jsp"%>
<html>
<head>
	<title>收货地址</title>
	<%@include file="/WEB-INF/views/mobile/include/head.jsp" %>
	<script type="text/javascript"> 
		var appId = '${appId}';
		$(document).ready(function() {
			
		});
		//打开删除确认面板
		function checkDelete(id){
			$("input[name='rId']").val(id);
			//$("#delPopup").popup("open");
			document.location="ievent://showAlert?fun=iEventDelAddressAlert()";
		}
		
		function iEventDelAddressAlert(){
			var result = {
				title:"系统提示",
				message:"确定删除该收货地址？",
				buttons:[
					{
						title:"确定",
						fun:"delAddress()" //函数名自定义的，根据json返回的fun节点值去调用相应的js函数
					},
					{
						title:"取消",
						fun:"" //同上，并且如果这里没给函数则直接执行提示层close关闭
					}	
				]		
				
			}
			if($global_isAndroid){
				window.control.showAlert(JSON.stringify(result));
				return;
			}
			return JSON.stringify(result);
		}
		
		//删除
        function delAddress(){
       		var id = $("input[name='rId']").val();
			window.location.href = "${ctxShop}/address/delete?id="+id+"&appId="+appId;
		}
		//新增地址
		function newAddress(){
			window.location.href = "${ctxShop}/address/form?user.id=${user.id}&appId="+appId;
		}
	</script>
	<script type="text/javascript"> 
		function iEventGetNavgitionInfo(){
			var result = {
				title:"收货地址",
			    leftBtn:{ 
			    	type:0,	//0只显示返回,1只显示关闭，2显示返回，关闭
					backFun:"iEventGoBack()"   //返回执行的事件，不带的话由iOS控制。
				}              
			};
			if($global_isAndroid){
				window.control.onJsComplete(JSON.stringify(result));
				return;
			}
			return JSON.stringify(result);
		}
		function iEventGoBack(){
			document.location="ievent://quitWebView";
		}
	</script>
</head>
<body data-role="page">
	<div role="main" class="ui-content">
		<tags:mbmessage content="${message}"/>
		<c:if test="${fn:length(page.list) > 0}">
		<ul data-role="listview">
		    <c:forEach items="${page.list}" var="address" varStatus="vs">
		    <li data-icon="false">
		    	<a data-transition="slide" href="javascript:" onclick="document.location='${ctxShop}/address/form?id=${address.id}&appId=${appId }'" style="padding-right: 45px; margin-right: 0em;background-color: ${address.defaultFlag==1?'#788BA8;color:#FFF':''}">
		    	${address.name }
		    	<p class="ui-li-aside" style="margin-top: -7px; font-size:17px;font-weight: normal;"><b>${address.phone }</b></p><br/>
		    	<span style="font-weight: normal;"><c:if test="${address.defaultFlag==1}">[默认]</c:if>${address.detailAddress }</span>
		    	</a>
		    	<c:if test="${address.defaultFlag==1}">
		    		<span style="position: absolute; top: 20px; right: 10px;"><img src="${ctxFront}/images/shop/default.png" width="30px"/></span>
		    	</c:if>
		    </li>
		    </c:forEach>
		</ul>
		</c:if>
		<c:if test="${fn:length(page.list) == 0}">
			<p style="position: relative; left: 50%; margin-left: -30px;">暂无收货地址.</p>
		</c:if>
		<div data-role="popup" id="delPopup" data-overlay-theme="b" data-theme="a" data-dismissible="false" style="max-width:400px;">
			<div data-role="header" data-theme="a">
		    	<h1>删除</h1>
		    </div>
		    <div role="main" class="ui-content">
		        <h3 class="ui-title">是否确定删除？</h3>
		        <input type="hidden" id="rId" name="rId" value=""/>
		        <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-a" onclick="delAddress()">确定</a>
		        <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-a" data-rel="back">返回</a>
		    </div>
		</div>
	</div>
	<div data-role="footer" data-position="fixed" class="ui-btn" style="margin-bottom: 0px;position:fixed;padding:0px">
		<div data-role="controlgroup" data-type="horizontal">
	 		<a href="#" onclick="newAddress()"><img src="${ctxFront}/images/shop/new_addr.png" style="height:40px"></img></a>
	    </div>
	</div>
</body>
</html>